package 获取锁对象;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Ticket1 implements Runnable {

	int ticket = 100;
	// 获取锁对象
	Lock lo = new ReentrantLock();

	@Override
	public void run() {
		while (true) {
			if (ticket == 0) {
				System.out.println("票卖完了");
				break;

			}
			lo.lock();
			if (ticket > 0) {
				try {
					Thread.sleep(1);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			System.out.println(Thread.currentThread().getName() + "正在卖票" + ticket--);
		}
		lo.unlock();
	}

}
